<?php
declare (strict_types = 1);

namespace app\command;

use app\api\services\MemberInfoService;
use app\common\models\Member\MemberNum;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class CommunityTransferCountZero extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('community:transfer:count:zero')
            ->setDescription('转让次数清零');
    }

    /**
     * @throws ModelNotFoundException
     * @throws DataNotFoundException
     * @throws DbException
     */
    protected function execute(Input $input, Output $output)
    {
        $output->writeln('转让次数清零开始:'.date('Y-m-d H:i:s'));
        $list = MemberNum::getInstance()->where('transfer_count','>',0)->select();
        if(empty($list)){
            return false;
        }
        foreach($list as $v){
            MemberInfoService::getInstance()->addCommunityTransferCount($v['user_id'],$v['transfer_count'],2,'','自动清零');
        }

        // 指令输出
        $output->writeln('转让次数清零结束:'.date('Y-m-d H:i:s'));
    }
}
